/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase - T18
 * <p>Powered by webrx On 2021-12-27 14:24:43
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T18 {
    void work() {
        String tn = Thread.currentThread().getName();
        for (int i = 0; i < 3; i++) {
            if (i == 1 && "T1".equals(tn)) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if ("T3".equals(tn)) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println(tn + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        var t = new T18();

        var t1 = new Thread(t::work, "T1");
        var t2 = new Thread(t::work, "T2");
        var t3 = new Thread(t::work, "T3");
        var t4 = new Thread(t::work, "T4");
        //线程分支一
        t1.start();
        t1.join();

        //线程分支二
        t2.start();
        t2.join();
        t3.start();
        t3.join();
        t4.start();


    }
}
